function login_ajax(c) {	
	if (typeof (c) == "undefined") {
		$("#login_dialog").data("callback", null)
	} else {
		$("#login_dialog").data("callback", c)
	}
	var b = $("#login_dialog");
	if (b.length == 0) {
		var a = '<div id="login_dialog" style="height:180px"><div class="tanchu_middle"><div class="dialog_middle_c">';
		a += '<div class="tanchu_middle_c_left">';
		a += '<form id="login_form" onsubmit="post_login_ajax();return false;"><div class="user_login_middle">';
		a += '<ol><label>\u7528\u6237\u540d\uff1a <input type="text" class="text_login" name="login_username" id="login_username" tabindex="100"></label></ol>';
		a += '<ol><label>\u5bc6\u3000\u7801\uff1a <input type="password" class="text_login" name="login_password" id="login_password" tabindex="101"></label></ol>';
		a += '<dl class="tc_btn_group"><dd><input type="submit" class="tc_btn_login" value="  " tabindex="102" onclick=""/></dd>';
		a += '<dd><input type="button" class="tc_btn_reg" value="  " tabindex="102" onclick="reg_ajax()"/></dd>';
		a += '</dl><div class="clearit"></div></div></form></div></div></div></div>';
		$("body").append(a);
		$("#login_dialog")
				.dialog(
						{
							resizable : false,
							width : 360,
							height : 200,
							title : "登录漫画家",
							modal : true,
							open : function() {
							},
							close : function() {
							}
						})
	} else {
		b.dialog("open")
	}
}
function post_login_ajax() {
	var b = $.trim($("#login_username").val());
	var a = $("#login_password").val();
	if (b == "") {
		showMsg("\u767b\u5f55\u8d26\u53f7\u4e0d\u80fd\u4e3a\u7a7a");
		return false
	}
	if (a == "") {
		showMsg("\u5bc6\u7801\u4e0d\u80fd\u4e3a\u7a7a");
		return false
	}
	$
			.ajax( {
				url : domain_url + "/Member/loginAjax.do",
				data : {
				username : b,
				password : a
				},
				type : "POST",
				cache : false,
				success : function(result) {
					var c = eval(result)[0];
					if (c.code > 0) {
						popMsg(c.message);
						$("#login_dialog").dialog("close");
					} else {
						showMsg(c.message)
					}
				},
				error : function() {
					showMsg("\u767b\u5f55\u5931\u8d25,\u670d\u52a1\u5668\u901a\u4fe1\u9519\u8bef")
				}
			})
}

function reg_ajax() {
	var b = $("#reg_dialog");
	if (b.length == 0) {
		var a = '<div id="reg_dialog" title="注册漫画家通行证" style="display:none" class="user_reg">';
		a += '<div class="line user_reg_content" style="padding-bottom:10px;">';
		a += '<dl><dt><label>\u767b\u5f55\u8d26\u53f7\uff1a<span>*</span></label><input class="text_reg" type="text" id="signup_username"/><span class="intro_info_text">5-15个字符</span></dt></dl>';
		a += '<dl><dt><label>\u6635\u3000\u3000\u79f0\uff1a<span>*</span></label><input class="text_reg" type="text" id="signup_nickname"/><span class="intro_info_text">2-10个字符</span></dt></dl>';
		a += '<dl><dt><label>\u5bc6\u3000\u3000\u7801\uff1a<span>*</span></label><input class="text_reg" type="password" id="signup_password" name="signup_password"/><span class="intro_info_text">3-15个字符</span></dt></dl>';
		a += ' <dl><dt><label>\u786e\u8ba4\u5bc6\u7801\uff1a<span>*</span></label><input class="text_reg" type="password" id="signup_cpassword"/></dt></dl>';
		a += '<dl><dt><label>\u7535\u5b50\u90ae\u7bb1\uff1a<span>*</span></label><input class="text_reg" type="text" id="signup_email"/><span class="intro_info_text">用于密码找回</span></dt></dl>';
		a += '<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input class="btn3" type="button" onclick="post_reg_ajax();return false;" value="\u5feb\u901f\u5b8c\u6210\u6ce8\u518c" /></li>';
		a += "</div></div>";
		$("body").append(a);
		b = $("#reg_dialog").dialog(
				{
					resizable : false,
					width : 450,
					height : 300,
					modal : true,
					open : function() {
					},
					close : function() {
					}
				});
	} else {
		b.dialog("open");
	}
}
function isEmail(str){
    var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/;
    return reg.test(str);
}
function post_reg_ajax() {
	var username = $.trim($("#signup_username").val());
	var password = $("#signup_password").val();
	var cpassword = $("#signup_cpassword").val();
	var nickname = $("#signup_nickname").val();
	var email = $("#signup_email").val();
	if (username == "") {
		showMsg("登录账号不能为空！");
		return false
	}
	if (username.length < 5 || username.length > 15) {
		showMsg("登录账号字符长度5-15");
		return false
	}
	if (nickname == "") {
		showMsg("昵称不能为空！");
		return false
	}
	if (nickname.length < 2 || nickname.length > 10) {
		showMsg("昵称字符长度2-10");
		return false
	}
	if (password == "") {
		showMsg("密码不能为空！");
		return false
	}
	if (password.length < 3 || password.length > 15) {
		showMsg("密码字符长度3-15");
		return false
	}
	if (cpassword == "") {
		showMsg("确认密码不能为空！");
		return false
	}
	if (password != cpassword) {
		showMsg("确认密码输入不正确，请重新输入！");
		return false
	}
	if (email == "") {
		showMsg("邮箱不能为空！");
		return false
	}
	if (!isEmail(email)) {
		showMsg("请输入正确的邮箱格式！");
		return false
	}
	var b = {
			'username' : username,
			'nickname' : nickname,
			'password' : password,
			'email' : email
		};
	var checkName = true;
	$
	.ajax( {
		url : domain_url + "/Member/checkAjax.do",
		data : {"username":username},
		type : "POST",
		cache : false,
		async:false,
		success : function(result) {
			if (result == 0) {
				checkName = false;
			}
		}
	});
	if (!checkName) {
		showMsg("登录账号已经被占用，请重新输入！");
		return false;
	}

	$
	.ajax( {
		url : domain_url + "/Member/registerAjax.do",
		data : b,
		type : "POST",
		cache : false,
		success : function(result) {
			var c = eval(result)[0];
			if (c.code > 0) {
				$("#reg_dialog").dialog("close");
				$("#login_dialog").dialog("close");
				popMsg(c.message);
			} else {
				showMsg(c.message);
			}
		},
		error : function() {
			showMsg("\u6ce8\u518c\u5931\u8d25,\u670d\u52a1\u5668\u901a\u4fe1\u9519\u8bef")
		}
	})
}

var callbackLogin = [];
var MessageTimeId = 0;
var SessionTimeId = 0;
function showMsgS(a) {
	showMsg(a, "\u5996\u6c14\u63d0\u793a", null, 3000)
}
var messageBoxIndex = 0;
function showMsg(q, w, s, f, o, m) {
	var v = f;
	messageBoxIndex++;
	o = typeof (o) == "undefined" ? 350 : o;
	m = typeof (m) == "undefined" ? 220 : m;
	content_height = m - 72;
	var n = "messageBox" + messageBoxIndex;
	$("body").append(
			'<div id="' + n + '" style="display:none;" title=""></div>');
	w = w == undefined ? "漫画家提示" : w;
	$("#" + n).attr("title", w);
	var j = $('<table width="100%" height="' + content_height + '" border="0" cellspacing="0" cellpadding="0"><tr><td class="messageBoxTd" align="center" valign="middle"></td></tr></table>');
	j.find(".messageBoxTd").append(q);
	$("#" + n).append(j);
	var k = function() {
	};
	var p = null;
	var c = "center";
	if (window.self != window.top) {
		var b = parent.document.documentElement.scrollTop;
		var a = parent.document.documentElement.clientHeight
				+ parent.document.documentElement.scrollTop;
		var d = parent.$("#frame_comment").position().top;
		var h = d + parent.$("#frame_comment").height();
		var l = Math.max(b, d);
		var e = Math.min(a, h);
		var u = (e + l) / 2 - d;
		if (e - l > 220) {
			u -= 110
		}
		var g = parent.$("#frame_comment").width();
		if (g > 350) {
			g = g / 2 - 175
		}
		c = [ g, u ]
	}
	if (v != undefined && v > 0) {
		k = function(x, y) {
			p = setTimeout(function() {
				$("#" + n).dialog("close")
			}, v)
		}
	}
	if (s == undefined) {
		s = {
			"\u786e\u5b9a" : function() {
				$(this).dialog("close")
			}
		}
	}
	var r = $("#" + n).dialog( {
		width : o,
		height : m,
		modal : true,
		draggable : true,
		buttons : s,
		resizable : false,
		position : c,
		open : k,
		close : function(y, x) {
			$("#" + n).dialog("destroy").remove();
			clearTimeout(p);
			$().enableSelection()
		}
	});
	r.parent().find("button:contains(\u786e\u5b9a)").addClass("left");
	return r
}
function get_user(a) {
	user = $(document).data("loginUser");
	if (user == undefined || user == null || a == true) {
		$.ajax( {
			url : domain_url + "/Member/loadUserInfo.do",
			type : "POST",			
			cache : false,
			async : false,
			success : function(result) {
				if (result != "") {
					var data = eval(result);
					if (data.length == 1) {
						user = {
								username : data[0].username,
								nickname : data[0].nickname,
								id : data[0].id								
							};
					}
				}
			}
		});
		
		$(document).data("loginUser", user)
	}
	return user
}
function get_user_setting(a) {
	var c = $.cookie("setting");
	var b = null;
	if (c != null && typeof (c) != "undefined") {
		b = $.evalJSON(c);
		if (typeof (a) != "undefined") {
			return b[a]
		}
	}
	return b
}
function set_user_setting(a, d) {
	var c = $.cookie("setting");
	var b = null;
	if (c != null && typeof (c) != "undefined") {
		b = $.evalJSON(c);
		b[a] = d
	} else {
		b = {};
		b[a] = d
	}
	$.cookie("setting", $.toJSON(b), {
		expires : 31536000,
		path : "/"
	})
}
(function(a) {
	var b = function() {
	};
	a.extend(b.prototype, {
		yes : "\u786e\u5b9a",
		no : "\u53d6\u6d88",
		title : "\u6d88\u606f\u63d0\u793a\u6846",
		msg : "\u64cd\u4f5c\u9519\u8bef"
	});
	a.confirmDialog = function(e, k) {
		var h = new b();
		a.extend(h, e);
		var g = 0;
		var d = function() {
			g = 1;
			a(this).dialog("close")
		};
		var c = function() {
			g = 0;
			a(this).dialog("close")
		};
		var f = new Object();
		f[h.yes] = d;
		if (h.no != "") {
			f[h.no] = c
		}
		var j = showMsg(h.msg, h.title, f);
		j.one("dialogclose", function() {
			if (g) {
				k()
			}
		});
		if (h.no != "") {
			j.parent().find("button:first").attr("class", "left");
			j.parent().find("button:last").attr("class", "right")
		}
	};
	a.confirmDialog.defaults = function(c) {
		a.extend(b.prototype, c)
	}
})(jQuery);
function popMsg(j, l, c, n) {
	if (typeof l == "undefined") {
		l = ""
	}
	if (typeof c == "undefined") {
		c = ""
	}
	var f = '<div class="exp"><div class="exp_top txt_ct">' + l + '</div><div class="exp_content"><i></i><p>';
	if (typeof (j) == "object") {
		for ( var e in j) {
			f += '<font class="red_bc font_14">' + e
					+ '</font><font class="font_18 blue_00 b">' + j[e]
					+ "</font>\u3000"
		}
	} else {
		f += '<font class="red_bc font_14">' + j + "</font>"
	}
	f += "<br />" + c + "</p></div></div>";
	var o = $(f).css("opacity", 0);
	if (n == "window" || typeof n == "undefined") {
		$("body").append(o);
		var m = $(window).scrollTop();
		var h = m + ($(window).height() / 5) * 3;
		var b = m + ($(window).height() / 5) * 2;
		var d = (($(window).width() - o.width()) / 2) + "px"
	} else {
		$(n).append(o);
		var a = height = pleft = ptop = 0;
		var k = {
			w : $(n).width(),
			h : $(n).height(),
			ol : $(n).offset().left,
			ot : $(n).offset().top,
			olw : $(n).offset().left + $(n).width(),
			oth : $(n).offset().top + $(n).height()
		};
		var g = {
			w : $(window).width(),
			h : $(window).height(),
			sL : $(window).scrollLeft(),
			sT : $(window).scrollTop(),
			sLw : $(window).scrollLeft() + $(window).width(),
			sTh : $(window).scrollTop() + $(window).height()
		};
		if (k.ol < g.sL) {
			pleft = g.sL - k.ol;
			if (k.olw > g.sLw) {
				a = g.w
			} else {
				if (k.olw > g.sL) {
					a = k.olw - g.sL
				}
			}
		} else {
			if (k.olw <= g.sLw) {
				a = k.w
			} else {
				if (k.ol < g.sLw) {
					a = g.sLw - k.ol
				}
			}
		}
		if (k.ot < g.sT) {
			ptop = g.sT - k.ot;
			if (k.oth > g.sTh) {
				height = g.h
			} else {
				if (k.oth > g.sT) {
					height = k.oth - g.sT
				}
			}
		} else {
			if (k.oth <= g.sTh) {
				height = k.h
			} else {
				if (k.ot < g.sTh) {
					height = g.sTh - k.ot
				}
			}
		}
		var h = ptop + (height - o.height()) / 5 * 3;
		var b = ptop + (height - o.height()) / 5 * 2;
		var d = pleft + ((a - o.width()) / 2) + "px"
	}
	o.css("left", d).css("top", h);
	o.animate( {
		opacity : 1,
		top : b
	}, 500, null, function() {
		setTimeout(function() {
			o.remove()
		}, 3000)
	})
}
